package qmlt.learning.knn.control;

import qmlt.dataset.Instance;

public class BasicKNNController implements KNNController
{

	private int	k;

	public BasicKNNController(int k, boolean distanceWeighted)
	{
		this.k = k;
	}

	@Override
	public int getK()
	{
		return k;
	}

	@Override
	public float getDistance(Instance inst1, Instance inst2)
	{
		assert (inst1.getFeatures().size() == inst2.getFeatures().size());
		int n = inst1.getFeatures().size();

		float s = 0;
		for (int i = 0; i < n; ++i)
		{
			float d = (Float) inst1.getFeatures().get(i) - (Float) inst2.getFeatures().get(i);
			s += d * d;
		}

		return (float) Math.sqrt(s);
	}

}
